/*
import 'package:flame/components.dart';
import 'package:flame/events.dart';
import 'package:flame/extensions.dart';
import 'package:flutter/material.dart';
import '../../../bloc/game_bloc/GameEvent.dart';
import '../../../config/GameConfig.dart';
import '../audio/SoundManager.dart';
import '../GameWorld.dart';
import '../entity/PlantEntity.dart';
import 'DragShadow.dart';
import 'LawnCell.dart';

// 植物菜单
@Deprecated("功能移动到SeedPacket")
class PlantButton extends SpriteComponent
    with HasWorldReference<GameWorld>, GameConfig, TapCallbacks, DragCallbacks {
  final PlantEntity plantEntity; // 植物模型类
  final Sprite cardSprite; // 卡片
  final Sprite preSetSprite; // 待种植植物
  late bool enablePlant; // 能否种植
  late double _coldTimeRemaining = 0; // 冷却时间
  // Colors.black就是常量啊
  // 使用常量定义颜色，避免重复创建
  // static const _disabledColor = Colors.black;
  // static const _coolDownColor = Colors.black;
  late final Paint _disabledPaint;
  late final Paint _coolDownPaint;
  late final Timer _coolDownTimer;

  PlantButton({
    required this.plantEntity,
    required this.cardSprite,
    required this.preSetSprite,
    super.position,
    super.size,
  }) {
    enablePlant = true;
    _coldTimeRemaining = 0;
    _disabledPaint = Paint()..color = Colors.black.withValues(alpha: 0.3);
    _coolDownPaint = Paint()..color = Colors.black.withValues(alpha: 0.6);
    _coolDownTimer = Timer(
      0.1,
      repeat: true,
      onTick: _handleCoolDownTick,
      autoStart: false,
    );
  }

  @override
  Future<void> onLoad() async {
    sprite = cardSprite;
    // 确保按钮的锚点设置正确，避免位置偏差
    anchor = Anchor.topLeft;
  }

  @override
  void update(double dt) {
    super.update(dt);
    if (_coldTimeRemaining >= 0) {
      _coolDownTimer.update(dt);
    }
  }

  @override
  void render(Canvas canvas) {
    super.render(canvas);
    if (world.bloc.state.sunlight < plantEntity.cost || !enablePlant) {
      canvas.drawRect(size.toRect(), _disabledPaint);
    }
    if (_coldTimeRemaining >= 0) {
      final coolDownHeight = size.y * (_coldTimeRemaining / plantEntity.cold);
      canvas.drawRect(
        Rect.fromLTWH(0, 0, size.x, coolDownHeight),
        _coolDownPaint,
      );
    }
  }

  // 开始冷却
  void startCoolDown() {
    enablePlant = false;
    _coldTimeRemaining = plantEntity.cold;
    _coolDownTimer.start();
  }

  void _handleCoolDownTick() {
    _coldTimeRemaining -= 0.1;
    if (_coldTimeRemaining <= 0) {
      _coldTimeRemaining = 0;
      enablePlant = true;
      _coolDownTimer.stop();
    }
  }

  @override
  void onDragStart(DragStartEvent event) {
    if (enablePlant && world.bloc.state.sunlight >= plantEntity.cost) {
      SoundManager().playChoosePlant();
      world.bloc.add(UpdateSelectedPlant(
        plantEntity: plantEntity,
        plantButton: this,
      ));
      // 创建拖动阴影
      world.dragShadow = DragShadow(preSetSprite);
      world.dragShadow!.position = position;
      world.add(world.dragShadow!);
    }
    super.onDragStart(event);
  }

  @override
  void onDragUpdate(DragUpdateEvent event) {
    world.dragShadow?.position += event.localDelta;
    super.onDragUpdate(event);
  }

  @override
  void onDragEnd(DragEndEvent event) {
    final shadowPosition = world.dragShadow!.position;
    final shadowSize = world.dragShadow!.size;
    final plantCenter = Vector2(
      shadowPosition.x + shadowSize.x / 2,
      shadowPosition.y + shadowSize.y / 2,
    );
    // 查找放置的草坪格子
    LawnCell? lawnCell;
    try {
      lawnCell = world.lawnCells.firstWhere(
        (cell) => cell.toRect().containsPoint(plantCenter),
      );
    } catch (_) {}

    if (lawnCell != null) {
      world.tryPlacePlant(lawnCell, plantEntity, this);
    }
    // 清理拖动状态
    world.dragShadow?.removeFromParent();
    world.dragShadow = null;
    world.bloc.add(UpdateSelectedPlant());
    super.onDragEnd(event);
  }
}
*/
